package com.xzj.admin.boot.controller;

import com.xzj.admin.boot.domain.entity.SysGatewayRouter;
import com.xzj.admin.boot.service.SysGatewayRouterService;
import com.xzj.common.datasource.domain.PageReq;
import com.xzj.common.datasource.domain.PageResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @program: xzj-admin
 * @ClassName: SysGatewayRouterController
 * @description: 网关路由管理;(sys_gateway_router)表控制层
 * @author: XiaZunJun
 * @create: 2024-10-12 14:31
 */
@Tag(name = "网关路由管理对象功能接口")
@RestController
@RequestMapping("/gateway/router")
public class SysGatewayRouterController{
    @Resource
    private SysGatewayRouterService sysGatewayRouterService;


    /**
     * 分页查询
     *
     * @param pageReq 分页筛选条件对象
     * @return 查询结果
     */
    @Operation(summary = "分页查询")
    @PostMapping("/pageQuery")
    public PageResp<SysGatewayRouter> pageQuery(@RequestBody PageReq<SysGatewayRouter> pageReq){
        return sysGatewayRouterService.pageQuery(pageReq);
    }

    /**
     * 新增数据
     *
     * @param sysGatewayRouter 实例对象
     * @return 实例对象
     */
    @Operation(summary ="新增Or更新数据")
    @PostMapping("/addOrUpdate")
    public SysGatewayRouter addOrUpdate(@RequestBody SysGatewayRouter sysGatewayRouter){
        if(sysGatewayRouter.isUpdate()){
            sysGatewayRouterService.update(sysGatewayRouter);
        }else{
            sysGatewayRouterService.insert(sysGatewayRouter);
        }
        return sysGatewayRouter;
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Operation(summary ="通过主键删除数据")
    @GetMapping("/deleteById/{id}")
    public boolean deleteById(@PathVariable(name = "id") String id){
        return sysGatewayRouterService.deleteById(id);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Operation(summary ="通过主键删除数据")
    @GetMapping("/config/deleteById/{id}")
    public boolean configDeleteById(@PathVariable(name = "id") String id){
        return sysGatewayRouterService.deleteRouterConfigsById(id);
    }
}
